package com.link2room.rodimus.handler.impl;

import com.link2room.common.constant.DefaultValue;
import com.link2room.common.dto.result.base.MemberSessionDto;
import com.link2room.common.dto.threadlocal.ApiThreadLocal;
import com.link2room.common.exception.SysException;
import com.link2room.common.util.L2RAssert;
import com.link2room.rodimus.feign.soundwave.PmsMemberFeignService;
import com.link2room.rodimus.handler.ISignInDrawAwardHandler;
import com.link2room.soundwave.dto.param.inside.PointPresentUseInsideParamDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;

import static com.link2room.enums.exception.RodimusSysExceptionEnum.SIGN_IN_ERROR;

/**
 * Created by LN on 2018/1/9
 */
@Component("signInDrawAwardPointHandler")
public class SignInDrawAwardPointHandler implements ISignInDrawAwardHandler {

    @Autowired
    private PmsMemberFeignService pmsMemberFeignService;
    @Override
    public void drawAward(String lhotelGroupCode, String type, String value) throws Exception {
        MemberSessionDto memberSession = ApiThreadLocal.getMemberSessionThreadLocal();
        L2RAssert.isTrue(null == memberSession, new SysException(SIGN_IN_ERROR, "请登录."));
        L2RAssert.isTrue(DefaultValue.F.equals(memberSession.getIsMember()), new SysException(SIGN_IN_ERROR, "请先注册会员."));
        String memberNo = memberSession.getMemberNo();
        PointPresentUseInsideParamDto pointPresentUseInsideParamDto = new PointPresentUseInsideParamDto();
        pointPresentUseInsideParamDto.setL2rMemberNo(memberNo);
        pointPresentUseInsideParamDto.setPoint(new BigDecimal(value));
        pointPresentUseInsideParamDto.setLhotelGroupCode(lhotelGroupCode);
        pmsMemberFeignService.addPoint(pointPresentUseInsideParamDto);
    }
}
